﻿using System;
using System.Collections.Generic;
using System.Web.Mvc;
using BabyShop.Site.Models;
using System.Linq;

namespace BabyShop.Site.Services
{
    public class EnumServices : BaseService<User>
    {
        public IEnumerable<ProductType> GetParentProductTypes(Guid selfGuid)
        {
            var parentPtQuery = DataServices.ProductTypes.Where(p => !p.CommonColumns.IsDelete);

            if (selfGuid != Guid.Empty)
                parentPtQuery = parentPtQuery.Where(p => p.ProductTypeGuid != selfGuid
                                                         && p.ParentGuid != selfGuid);

            return parentPtQuery;
        }

        public IEnumerable<ProductType> GetAllProductTypes(bool ignoreIsDelete = false)
        {
            return DataServices.ProductTypes.Where(p =>
                                                   p.CommonColumns.IsDelete == ignoreIsDelete ||
                                                   p.CommonColumns.IsDelete == false);
        }

        public IEnumerable<ProductType> GetLastProductTypes()
        {
            return
                DataServices.ProductTypes.Where(p => !DataServices.ProductTypes.Any(m => m.ParentGuid == p.ProductTypeGuid));
        }

        public IEnumerable<ProductType> GetSameProductTypes(Guid productTypeGuid, Guid? currentGuid = null)
        {
            return
                DataServices.ProductTypes.Where(p => !p.CommonColumns.IsDelete
                                                     && p.ParentGuid == productTypeGuid
                                                     && p.ProductTypeGuid != (currentGuid ?? Guid.Empty));
        }
    }
}